/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.util.GregorianCalendar;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Document;

/**
 *
 * @author Ira
 */
public class TableDocument extends AbstractTableModel {	
	private String[] headers = {"Type","Titre", "Année", "Auteurs", "Editeur", "Disponibilité"};
	private Document[] docs;

	public TableDocument(Document[] docs) {
		this.docs = docs;
	}
        
	@Override
	public int getRowCount() {
		return this.docs == null ? 0: this.docs.length;
	}

	@Override
	public int getColumnCount() {
		return this.headers.length;
	}
	
	@Override
	public String getColumnName(int columnIndex) {
		return this.headers[columnIndex];
    }

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch(columnIndex) {
			case 0:
				return this.docs[rowIndex].getCategory();
			case 1:
				return this.docs[rowIndex].getTitle();
			case 2:
				return this.docs[rowIndex].getYear();
			case 3:
				return this.docs[rowIndex].getAuthors();
			case 4:
				return this.docs[rowIndex].getEditor();
			case 5:
				return this.docs[rowIndex].getDateAvaillable();
			default:
				return null;
		}
	}
	
	@Override
	public Class getColumnClass(int columnIndex){
		switch(columnIndex){
			case 3:
				return List.class;
			case 5:
				return GregorianCalendar.class;
			default:
				return Object.class;
		}
	}
}
